package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.TourGroup;
import com.ruoyi.system.domain.TourPackage;
import com.ruoyi.system.domain.vo.TourSmallPackage;
import com.ruoyi.system.domain.vo.TourSmallWorker;
import com.ruoyi.system.service.ITourGroupService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("tourgroup")
public class TourGroupController {

    @Resource
    private ITourGroupService groupService;

    @RequestMapping("/list")
    @ResponseBody
    public AjaxResult list() {
        try {
            List<TourGroup> groups = groupService.selectGroupList();
            return AjaxResult.success(groups);
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }

    @RequestMapping("/detail")
    @ResponseBody
    public AjaxResult detail(@RequestParam("id") int id) {
        try {
            TourGroup group = groupService.selectGroupDetail(id);
            return AjaxResult.success(group);
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }

    @RequestMapping("/delete")
    @ResponseBody
    public AjaxResult delete(@RequestParam("id") int id) {
        try {
            groupService.deleteGroup(id);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }

    @RequestMapping("/create")
    @ResponseBody
    public AjaxResult delete(@RequestBody TourGroup group) {
        try {
            groupService.createGroup(group);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }

    @RequestMapping("/update")
    @ResponseBody
    public AjaxResult update(@RequestBody TourGroup group) {
        try {
            groupService.updateGroup(group);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }

    @RequestMapping("/selectpackage")
    @ResponseBody
    public AjaxResult update(@RequestParam int id) {
        try {
            List<TourSmallPackage> packages = groupService.selectPackageOfCity(id);
            return AjaxResult.success(packages);
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }

    @RequestMapping("/selectworker")
    @ResponseBody
    public AjaxResult selectWorkerOfGroup() {
        try {
            List<TourSmallWorker> workers = groupService.selectWorkerOfGroup();
            return AjaxResult.success(workers);
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }
}
